package com.xy.biz.rs.domain.converter;

import java.util.Collection;
import java.util.List;

import com.xy.biz.rs.domain.bo.MaterialBO;
import com.xy.biz.rs.domain.po.MaterialPO;
import com.xy.biz.rs.domain.query.MaterialQuery;
import com.xy.biz.rs.domain.resp.GetMaterialResponse;
import com.xy.biz.rs.domain.req.SaveMaterialRequest;
import com.xy.biz.rs.domain.req.ListMaterialRequest;
import com.xy.tool.util.BeanUtilsEx;

/**
 *
 *
 * @author yzh
 * @date 2021-4-14
 */
public class MaterialConverter {

	public static MaterialPO toPO(MaterialBO source) {
		return BeanUtilsEx.copyProperties(source, () -> new MaterialPO(), true);
	}

	public static List<MaterialPO> toPO(Collection<MaterialBO> source) {
		return BeanUtilsEx.copyPropertiesForNewList(source, () -> new MaterialPO(), true);
	}

	public static MaterialBO fromPO(MaterialPO source) {
		return BeanUtilsEx.copyProperties(source, () -> new MaterialBO());
	}

	public static List<MaterialBO> fromPO(Collection<MaterialPO> source) {
		return BeanUtilsEx.copyPropertiesForNewList(source, () -> new MaterialBO());
	}

	public static MaterialBO toBO(SaveMaterialRequest source) {
		return BeanUtilsEx.copyProperties(source, () -> new MaterialBO(), true);
	}

	public static List<MaterialBO> toBO(Collection<SaveMaterialRequest> source) {
		return BeanUtilsEx.copyPropertiesForNewList(source, () -> new MaterialBO(), true);
	}

	public static GetMaterialResponse toResponse(MaterialBO source) {
		return BeanUtilsEx.copyProperties(source, () -> new GetMaterialResponse());
	}

	public static List<GetMaterialResponse> toResponse(Collection<MaterialBO> source) {
		return BeanUtilsEx.copyPropertiesForNewList(source, () -> new GetMaterialResponse());
	}

	public static MaterialQuery toQuery(ListMaterialRequest source) {
		if(null == source) {
			return null;
		}
		MaterialQuery target = new MaterialQuery(source.getPageIndex(), source.getPageSize());
		BeanUtilsEx.copyProperties(source, target);
		return target;
	}

}
